package com.wuhao.lib_common.utils;

import android.content.Context;
import android.content.SharedPreferences;

import com.wuhao.lib_common.configure.HttpConfig;


/**
 * @author zhangjianhao
 * @date 2021/6/15
 */
public class DataStoreUtils {

    public static void inputIpInfo(Context context, String ipAddress, String port) {
        SharedPreferences ipSp = context.getSharedPreferences(HttpConfig.NAME_IP_DATASTORE, Context.MODE_PRIVATE);
        SharedPreferences portSp = context.getSharedPreferences(HttpConfig.NAME_PORT_DATASTORE, Context.MODE_PRIVATE);

        SharedPreferences.Editor ipEditor = ipSp.edit();
        SharedPreferences.Editor portEditor = portSp.edit();
        ipEditor.putString(HttpConfig.KEY_IP_DATASTORE, ipAddress);
        ipEditor.apply();

        portEditor.putString(HttpConfig.KEY_PORT_DATASTORE, port);
        portEditor.apply();
    }

    public static String readIpInfo(Context context) {
        SharedPreferences ipSp = context.getSharedPreferences(HttpConfig.NAME_IP_DATASTORE, Context.MODE_PRIVATE);
        String ipSpString = ipSp.getString(HttpConfig.KEY_IP_DATASTORE, "");
        return ipSpString;
    }

    public static String readPortInfo(Context context) {
        SharedPreferences portSp = context.getSharedPreferences(HttpConfig.NAME_PORT_DATASTORE, Context.MODE_PRIVATE);
        String portSpString = portSp.getString(HttpConfig.KEY_PORT_DATASTORE, "");
        return portSpString;

    }

    public static String NAME_EXPORT_PASSWORD = "NAME_EXPORT_PASSWORD";
    public static String KEY_EXPORT_PASSWORD = "KEY_EXPORT_PASSWORD";
    public static void putExportPassword(Context context,String passwordStr){
        SharedPreferences passwordSp = context.getSharedPreferences(NAME_EXPORT_PASSWORD, Context.MODE_PRIVATE);
        SharedPreferences.Editor pwEditor = passwordSp.edit();
        pwEditor.putString(KEY_EXPORT_PASSWORD, passwordStr);
        pwEditor.apply();
    }
    public static String readExportPassword(Context context) {
        SharedPreferences ipSp = context.getSharedPreferences(NAME_EXPORT_PASSWORD, Context.MODE_PRIVATE);
        String passwordStr = ipSp.getString(KEY_EXPORT_PASSWORD, "");
        return passwordStr;
    }
}
